/**
 * @file    file.h
 * @brief 
 * @author  name
 * @version 1.0.1
 * @date 2023-04-17
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-17 <td>1.0.1     <td>name     <td>首次创建
 * </table>
 */

#ifndef __DEV_EEP_24CXX_H_
#define __DEV_EEP_24CXX_H_

/* file includes -------------------------------------------------------------*/
#include "mcu_type.h"
#include "FreeRTOS.h"
#include "task.h"
/* cplusplus -----------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

/* macro/define/typedef ------------------------------------------------------*/
//enum
//{
//    EEP_24C01 ,
//    EEP_24C02 ,
//    EEP_24C04 ,
//    EEP_24C08 ,
//    EEP_24C16 ,
//    EEP_24C32 ,
//    EEP_24C64 ,
//    EEP_24C128 ,
//    EEP_24C256 ,
//    EEP_24C512 ,
//    EEP_24C1024 , 
//};

#define EEP_24C512            /* !< 定义EEP类型*/
#define EEP_DRV_I2C          (DRV_I2C1)        /* !< I2C 驱动接口*/
//#define eep_delay_ms         mcu_delay_ms      /* !< ms延时函数 */
#define eep_delay_ms         vTaskDelay      /* !< ms延时函数 */
/**
 * @brief 定义EEPROM 类型参数
 */
#ifdef EEP_24C01
    #define EEP_MODEL_NAME "AT24C01"
    #define EEP_DEV_ADDR   0xA0  /* 设备地址 */
    #define EEP_PAGE_SIZE  8     /* 页面大小(字节) */
    #define EEP_CAPACITY   128   /* 总容量(Byte) */
    #define EEP_ADDR_BYTES 1     /* 地址字节个数 */
    #define EEP_ADDR_A8    0     /* 扩展地址 1: 使能 */
#endif 

#ifdef EEP_24C02
    #define EEP_MODEL_NAME "AT24C02"
    #define EEP_DEV_ADDR   0xA0  
    #define EEP_PAGE_SIZE  8    
    #define EEP_CAPACITY   256   
    #define EEP_ADDR_BYTES 1     
    #define EEP_ADDR_A8    0
#endif

#ifdef EEP_24C04
    #define EEP_MODEL_NAME "AT24C04"
    #define EEP_DEV_ADDR   0xA0  
    #define EEP_PAGE_SIZE  8     
    #define EEP_CAPACITY   512   
    #define EEP_ADDR_BYTES 1    
    #define EEP_ADDR_A8    1
#endif 

#ifdef EEP_24C08  
    #define EEP_MODEL_NAME "AT24C08"
    #define EEP_DEV_ADDR   0xA0  
    #define EEP_PAGE_SIZE  16   
    #define EEP_CAPACITY   1024
    #define EEP_ADDR_BYTES 2   
    #define EEP_ADDR_A8    1
#endif

#ifdef EEP_24C16
    #define EEP_MODEL_NAME "AT24C16"
    #define EEP_DEV_ADDR   0xA0   
    #define EEP_PAGE_SIZE  16    
    #define EEP_CAPACITY   2048
    #define EEP_ADDR_BYTES 2 
    #define EEP_ADDR_A8    1   
#endif

#ifdef EEP_24C32
    #define EEP_MODEL_NAME "AT24C32"
    #define EEP_DEV_ADDR   0xA0   
    #define EEP_PAGE_SIZE  32    
    #define EEP_CAPACITY   4096
    #define EEP_ADDR_BYTES 2  
    #define EEP_ADDR_A8    1
#endif

#ifdef EEP_24C64 
    #define EEP_MODEL_NAME "AT24C64"
    #define EEP_DEV_ADDR   0xA0 
    #define EEP_PAGE_SIZE  32    
    #define EEP_CAPACITY   8192
    #define EEP_ADDR_BYTES 2    
    #define EEP_ADDR_A8    1  
#endif

#ifdef EEP_24C128  
    #define EEP_MODEL_NAME "AT24C128"
    #define EEP_DEV_ADDR   0xA0 
    #define EEP_PAGE_SIZE  32    
    #define EEP_CAPACITY   16384
    #define EEP_ADDR_BYTES 2    
    #define EEP_ADDR_A8    0 
#endif

#ifdef EEP_24C256  
    #define EEP_MODEL_NAME "AT24C256"
    #define EEP_DEV_ADDR   0xA0 
    #define EEP_PAGE_SIZE  32    
    #define EEP_CAPACITY   32768
    #define EEP_ADDR_BYTES 2 
    #define EEP_ADDR_A8    0
#endif

#ifdef EEP_24C512
    #define EEP_MODEL_NAME "AT24C256"
    #define EEP_DEV_ADDR   0xA0 
    #define EEP_PAGE_SIZE  32    
    #define EEP_CAPACITY   65536 /* 64K*/
    #define EEP_ADDR_BYTES 2 
    #define EEP_ADDR_A8    0
#endif

#ifdef EEP_24M01 
    #define EEP_MODEL_NAME "AT24M01"
    #define EEP_DEV_ADDR   0xA0 
    #define EEP_PAGE_SIZE  62    
    #define EEP_CAPACITY   (128 * 1024) /* 64K*/
    #define EEP_ADDR_BYTES 2 
    #define EEP_ADDR_A8    1
#endif
/* @brief */

/* variables -----------------------------------------------------------------*/

/*******************************************************************************
 * public API List
 ******************************************************************************/
uint8_t dev_eep_check_online(void);
uint8_t dev_eep_read_bytes(uint32_t eep_addr, uint8_t *rd_buf, uint32_t read_size);
uint8_t dev_eep_write_bytes(uint32_t eep_addr, uint8_t *wr_buf, uint32_t size);
uint32_t dev_eep_get_capacity(void);
void eep_24xx_drv_test(void);

#ifdef __cplusplus
}
#endif

#endif  /* #ifndef __DEV_EEP_24CXX_H_ */
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/

